﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

using QLTTAN.DTO;
namespace QLTTAN.DAL
{
    public class LopHocDAL
    {
        ConnectionData conn;

        public DataRow LopHoc_GetInfo(LopHocDTO LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaLop";
            value[0] = LH_DTO.MaLop;

            return conn.GetData("LOPHOC_GETINFO", name, value, Nparameter).Rows[0];
        }

        public DataRow LopHoc_GetLastID()
        {
            conn = new ConnectionData();
            return conn.GetData("LOPHOC_LASTID").Rows[0];
        }

        public DataTable LopHoc_Load(LopHocDTO LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaKhoaHoc";
            value[0] = LH_DTO.MaKhoaHoc;

            return conn.GetData("LOPHOC_IN_KHOAHOC", name, value, Nparameter);
        }

        public DataTable LopHoc_Load_MaxKhoaHoc()
        {
            conn = new ConnectionData();

            return conn.GetData("LOPHOC_LOAD_Max_KhoaHoc");
        }

        public DataTable LopHoc_LoadCungTrinhDo(LopHocDTO LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 2;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaKhoaHoc";
            value[0] = LH_DTO.MaKhoaHoc;
            name[1] = "MaLop";
            value[1] = LH_DTO.MaLop;

            return conn.GetData("LOPHOC_LOAD_MaLopMaKhoa", name, value, Nparameter);
        }

        public int LopHoc_Insert(LopHocDTO LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 5;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaKhoaHoc";
            value[0] = LH_DTO.MaKhoaHoc;
            name[1] = "MaLoaiLop";
            value[1] = LH_DTO.MaLoaiLop;
            name[2] = "MaPhongHoc";
            value[2] = LH_DTO.MaPhongHoc;
            name[3] = "NgayBatDau";
            value[3] = LH_DTO.NgayBatDau;
            name[4] = "NgayKetThuc";
            value[4] = LH_DTO.NgayKetThuc;

            return conn.UpdateData("LOPHOC_INSERT", name, value, Nparameter);
        }

        public int LopHoc_Update(LopHocDTO LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 6;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaLop";
            value[0] = LH_DTO.MaLop;
            name[1] = "MaKhoaHoc";
            value[1] = LH_DTO.MaKhoaHoc;
            name[2] = "MaLoaiLop";
            value[2] = LH_DTO.MaLoaiLop;
            name[3] = "MaPhongHoc";
            value[3] = LH_DTO.MaPhongHoc;
            name[4] = "NgayBatDau";
            value[4] = LH_DTO.NgayBatDau;
            name[5] = "NgayKetThuc";
            value[5] = LH_DTO.NgayKetThuc;

            return conn.UpdateData("LOPHOC_UPDATE", name, value, Nparameter);
        }

        public int LopHoc_Delete(LopHocDTO LH_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaLop";
            value[0] = LH_DTO.MaLop;

            return conn.UpdateData("LOPHOC_DELETE", name, value, Nparameter);
        }
    }
}
